<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : own_shopmessage.php   FILE_PATH : D:\webroot\mulitishop\member\own_shopmessage.php
 * ....商铺留言管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Wed Sep 12 10:44:51 CST 2007
 */

require_once("../global.inc.php");

class OwnShopMessageManage extends CommonFrameWork{
	/**
	 * 商铺留言对象
	 *
	 * @var obj
	 */
	var $obj_shopmessage;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	/**
	 * 网站提醒对象
	 *
	 * @var obj
	 */
	var $obj_remind;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	
	function main(){
		//$shop_id = $_SESSION['shop']['id'];

		/**
		 * 创建商铺分类对象
		 */
		if (!is_object($this->obj_shopmessage)){
			require_once("shopmessage.class.php");
			$this->obj_shopmessage = new ShopMessageClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 创建分页对象
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");

		/**
		 * 语言包
		 */
		$this->getlang("shop");




		/**
		 * 根据参数调用相应的方法
		 */
		switch ($this->_input['action']){
			case "del":
				$this->_delMessage();
				break;
			case "addsave":
				$this->_saveAddMessage();
				break;
			case "re":
				$this->shopMenuModule();
				$this->_reMessage();
				break;
			case "add":
				$this->shopMenuModule();
				$this->_addMessage();
				break;
			case "resave";
			$this->_saveReMessage();
			break;
			default:
				$this->shopMenuModule();
				$this->_getMessageList();
		}
	}

	/**
	 * 得到留言列表
	 *
	 */
	function _getMessageList(){
		$this->obj_page->pagebarnum(20);    //每页20条记录
		$message_array = $this->obj_shopmessage->getMessage($this->obj_page,$_SESSION['s_shop']['id']);     //得到留言列表
		$pagelist = $this->obj_page->show(1);      //分页显示
		$this->output('shop_message_array',$message_array);    //输出商铺留言列表
		$this->output('shop_message_pagelist',$pagelist);      //输出商铺留言分页
		$this->showpage('own_shopmessage.manage');
	}

	/**
	 * 删除留言
	 *
	 */
	function _delMessage(){
		$this->obj_shopmessage->deleteOperateMessage($this->_input['messageid'],$_SESSION['s_shop']['id']);
		$this->redirectPath("succ","/member/own_shopmessage.php","您删除留言成功！");
	}

	/**
	 * 保存店主发表留言
	 *
	 */
	function _saveAddMessage(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtMessage"],"require"=>"true","message"=>"请填写留言内容")
		);
		/**
		 * 检验的错误信息
		 */
		$error = $this->objvalidate->validate();
		if ($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			$this->_input['MemberName'] = $_SESSION['s_login']['name'];
			$this->_input['hideShopID'] = $_SESSION['s_shop']['id'];
			$this->obj_shopmessage->addMessage($this->_input);   //将留言内容存放到数据库中
			$this->redirectPath("succ","/member/own_shopmessage.php","您发表留言成功！");
		}
	}

	/**
	 * 发表留言
	 *
	 */
	function _addMessage(){
		$this->showpage('own_shopmessage.add');
	}

	/**
	 * 回复留言
	 *
	 */
	function _reMessage(){
		$message_array = $this->obj_shopmessage->getOneMessage($this->_input['messageid'],$_SESSION['s_shop']['id']);    //得到某条留言内容
		$this->output('shop_message_array',$message_array);   //输出留言内容
		$this->showpage('own_shopmessage.re');
	}

	/**
	 * 保存回复留言
	 *
	 */
	function _saveReMessage(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtReMessage"],"require"=>"true","message"=>"请填写回复内容")
		);
		/**
		 * 检验的错误信息
		 */
		$error = $this->objvalidate->validate();
		if ($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			$this->_input['hideShopID'] = $_SESSION['s_shop']['id'];
			$this->obj_shopmessage->reMessage($this->_input);   //将留言内容存放到数据库中
			
			/**
		     * 创建网站邮件发送内容信息对象
		     */
			if (!is_object($this->objcontent)){
				require_once("mailcontent.class.php");
				$this->objcontent = new MailContentClass();
			}
			$content = $this->objcontent->getMailContent("shopreply");   //获得发信内容

			if ($content['ifopen']){
				$message_array = $this->obj_shopmessage->getOneMessage($this->_input['hideMessageID'],$_SESSION['s_shop']['id']);   //得到留言内容
				require_once("shop.class.php");
				$obj_shop = new ShopClass();
				$shop_array = $obj_shop->getOneShop($_SESSION['s_shop']['id']);  //得到商店信息
				/**
		         * 创建发信对象
		         */
				if (!is_object($this->objmail)){
					require_once("sendmail.class.php");
					//$this->objmail = new SendMail($this->_configinfo['websit']['smtpserver'],$this->_configinfo['websit']['smtpprot'],true,$this->_configinfo['websit']['smtpuser'],$this->_configinfo['websit']['smtppass']);
				}
				$param = array(
				'shopname'=>$shop_array['shopname'],
				'website'=>$this->_configinfo['websit']['site_title'],
				'site_url'=>$this->_configinfo['websit']['site_url'],
				'question'=>$message_array['message_content'],
				'messagetime'=>date("Y-m-d h:s",$message_array['message_time']),
				'reply'=>$message_array['message_recontent'],
				'username'=>$message_array['member_name'],
				'mastername'=>$shop_array['login_name']
				);
				$content['content'] = Common::replaceMailContent($param,$content['content']);   //将发信内容的变量换为值
				$content['title'] = Common::replaceMailContent($param,$content['title']);       //将发信标题的变量换为值
				echo $content['title'] . $content['content'];
				//$this->objmail->send($this->_input['txtemail'],$this->_configinfo['websit']['smtpemail'],$this->_configinfo['websit']['site_name'],$content['title'],$content['content']);   //发信
			}
			
			$message_array = $this->obj_shopmessage->getOneMessage($this->_input['hideMessageID'],$_SESSION['s_shop']['id']);   //得到留言内容
			/**
			 * 网站提醒操作
			 */
			if (!is_object($this->obj_remind)){
				require_once('remind.class.php');
				$this->obj_remind = new RemindClass();
			}
			$shop_array = $this->storeBaseInfo();    //店铺基本信息
			$value_array = array();
			$value_array['username'] = $message_array['member_name'];
			$value_array['product_name'] = $shop_array['shop_name'];
			$this->obj_remind->setMessageOrMail('sale_message_seller_product_answer','message_seller_product_answer',$value_array,$message_array['member_name'],$this->_configinfo);

			
			$this->redirectPath("succ","/member/own_shopmessage.php","您回复留言成功！");
		}
	}
}
$message = new OwnShopMessageManage();
$message->main();
unset($message);
?>